#include "yuandong.h"
#include <Mesh_IO/Mesh_IO.h>
#include<Mesh/libcell_iterator.h>

#include <tool/libcell_tools_view.h>


#define quote lib_cell_quote
#define _ReadPly_ LibCell_ReadPly_




MY_CAPI_EXPORTS void yuandong_func(char*filename,float**v, unsigned int**f,  int *n)
{
    Mesh mesh;
    Mesh_init(&mesh); 
    _ReadPly_(&mesh,filename);
    n[0]=mesh.num_v(&mesh);//n[1]=mesh.num_c(&mesh);
    n[1]=0;
    *v=(float*)malloc(sizeof(float)*3*n[0]);
    for(auto cit=mesh.c_begin(&mesh);cit!=mesh.c_end(&mesh);cit++)
    {
        n[1]+=(quote(cit)->vertices_size+1);
    }
    *f=(unsigned int*)malloc(sizeof(unsigned int)*n[1]);
    int i=0;
    for(auto cit=mesh.c_begin(&mesh);cit!=mesh.c_end(&mesh);cit++)
    {
        (*f)[i]=quote(cit)->vertices_size;
        i++;
        for(int j=0;j<quote(cit)->vertices_size;j++)
        {
            (*f)[i]=quote(cit)->vertices[j]->id;
            i++; 
        }
    }  


    // get_data_from_2dim_cell(&mesh,v,f);



    


    Mesh_free(&mesh); 
}